package com.example.jmmconsumerkotlin

import android.os.Bundle
import android.widget.Toast
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import com.ashokvarma.bottomnavigation.BottomNavigationBar
import com.ashokvarma.bottomnavigation.BottomNavigationItem
import com.example.jmmconsumerkotlin.fragments.FragmentA
import com.example.jmmconsumerkotlin.fragments.FragmentB
import com.example.jmmconsumerkotlin.main.MainPresenter
import com.example.jmmconsumerkotlin.main.Maincontact
import com.example.jmmconsumerkotlin.base.YstarMvpBaseAct
import com.socks.library.KLog
import com.trello.rxlifecycle3.android.ActivityEvent
import com.ystarkotlin.utils.MyViewPagerAdapter
import io.reactivex.*
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Retrofit
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
import java.util.concurrent.Callable
import kotlin.concurrent.thread
import android.R.string
import androidx.core.content.ContextCompat.getSystemService
import com.example.jmmconsumerkotlin.di.T
import com.trello.rxlifecycle3.RxLifecycle.bindUntilEvent
import retrofit2.Response
import java.io.IOException


class MainActivity : YstarMvpBaseAct<Maincontact.IMainPresenter>(), Maincontact.IMainView,
    BottomNavigationBar.OnTabSelectedListener {

    override fun registerPresenter(): Class<out MainPresenter> = MainPresenter::class.java

    override fun layoutRes(): Int {
        return R.layout.activity_main
    }


    override fun getSuc() {
        KLogUtils("获取成功")
    }

    override fun getError() {
        KLogUtils("获取失败")
    }


    val fragments = listOf(
        FragmentA.newInstance("12", "232"),
        FragmentB.newInstance("12", "232"),
        FragmentB.newInstance("12", "232"),
        FragmentA.newInstance("12", "232")
    )
    var fragmentManager: FragmentManager = supportFragmentManager


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setM_bottomNavigationBar()
        setViwePager()
        setToolBarGone()
        showLaod("加载中，")
    }

    override fun initdata() {
        super.initdata()

    }

    fun setViwePager() {
        main_viewpaper.adapter = MyViewPagerAdapter(fragmentManager, fragments)
        main_viewpaper.setOffscreenPageLimit(fragments.size)
        main_viewpaper.setCurrentItem(0)

    }

    private fun setM_bottomNavigationBar() {
        m_bottomNavigationBar
            .setMode(BottomNavigationBar.MODE_FIXED)
            .setActiveColor(R.color.theme_color)
            .setInActiveColor(R.color.textColorTitle1D)
            .setTabSelectedListener(this)
            .addItem(
                BottomNavigationItem(R.drawable.home_r, "首页").setInactiveIcon(
                    ContextCompat.getDrawable(
                        this,
                        R.drawable.home_b
                    )
                )
            )
            .addItem(
                BottomNavigationItem(R.drawable.eye_r, "监控").setInactiveIcon(
                    ContextCompat.getDrawable(
                        this,
                        R.drawable.eye_b
                    )
                )
            )
            .addItem(
                BottomNavigationItem(R.drawable.c_r, "消息").setInactiveIcon(
                    ContextCompat.getDrawable(
                        this,
                        R.drawable.c_b
                    )
                )
            )
            .addItem(
                BottomNavigationItem(
                    R.drawable.gear_r,
                    "更多"
                ).setInactiveIcon(
                    ContextCompat.getDrawable(
                        this
                        , R.drawable.gear_b
                    )
                )
            )
            .initialise()

    }

        var  disposable :CompositeDisposable = CompositeDisposable()
    override fun onTabSelected(position: Int) {

        when (position) {
            0 -> Toast.makeText(this, "点击:第1", Toast.LENGTH_SHORT).show()
            1 -> Toast.makeText(this, "点击:第2", Toast.LENGTH_SHORT).show()
            2 -> Toast.makeText(this, "点击:第3", Toast.LENGTH_SHORT).show()
            3 -> Toast.makeText(this, "点击:第4", Toast.LENGTH_SHORT).show()
        }

        main_viewpaper.setCurrentItem(position)
    }

    override fun onTabReselected(position: Int) {

    }

    override fun onTabUnselected(position: Int) {
    }


    fun  setob(): Observable<*> {
/*
        return Observable.create<Any>{
            ObservableOnSubscribe<Integer> {

            }

        }
*/
            return Observable.defer{ObservableSource<String>{ println("123123123") }}
            return Observable.defer { ObservableSource<String> { KLog.a("12321") } }

    }


}


